import Vue from 'vue'
import App from './App.vue'
import router from './router'
import './plugins/element.js'
import axios from 'axios'
import './assets/css/global.css'

axios.defaults.baseURL = 'https://api.luoqianyi.top'
Vue.prototype.$axios = axios
// 点击回到页面顶部
Vue.prototype.toTop = function () {
  document.body.scrollTop = document.documentElement.scrollTop = 0
}
// 回到页面底部
Vue.prototype.toBottom = function (i) {
  const clientHeight = document.documentElement.clientHeight || document.body.clientHeight
  const scrollHeight = document.documentElement.scrollHeight
  const rollheight = scrollHeight - clientHeight // 超出窗口上界的值就是底部的scrolTop的值
  document.documentElement.scrollTop += 200
  if (document.documentElement.scrollTop + 1 <= rollheight) { // 之所以+1，可以打印这两个值的日志就知道了，下面+1也是同理
    var c = setTimeout(() => this.toBottom(i), 10)// 调用setTimeout是为了“回到底部”这过程不是一瞬间
  } else {
    clearTimeout(c)
  }
}
// 去除特殊字符
Vue.prototype.removeSpecialChar = function (s) {
  const pattern = /[\u4E00-\u9FA5A-Za-z0-9_,，。.“”]{1}/
  var rs = ''
  for (let i = 0; i < s.length; i++) {
    var single = s.substr(i, 1)
    if (single.match(pattern)) {
      rs = rs + single
    }
  }
  return rs
}

Vue.config.productionTip = false

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
